Skip to content

fix: overloading behaviour #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 8, 2024
Merged

Conversation

yani
Copy link
Contributor

@yani yani commented Jan 10, 2023

This code:

$session['a'][] = 'test';

Resulted in the following error:

Indirect modification of overloaded element of Compwright\PhpSession\Session has no effect

This PR makes the magic getter methods act as references.

It will behave like a normal array then.

The reason I added clone in the read tests is because I think the original PHP error is thrown when the variable is actually being used instead of just being referenced. "Using" the variable with clone fixes the test.

I think I understand everything correctly and fixed this. You can see how the tests fail if you remove the reference tokens (&) from the methods.

@yani
Copy link
Contributor Author

yani commented Jan 10, 2023

Ok I'm unsure what I did wrong.

Maybe this should have only been changed for array access.

(I only ran tests and not phpstan locally, my bad!)

@yani
Copy link
Contributor Author

yani commented Jan 22, 2023

@compwright have you looked into this?

Copy link
Owner

@compwright compwright left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix the lint errors.

On the clone statements, I don't see why they are needed. If they are, perhaps you meant to clone $this->session rather than $this->session->{var}.

Copy link
Owner

@compwright compwright left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yani tests continue to fail even after removing clone. Please fix the test failures, and I will be happy to merge this in.

@yani
Copy link
Contributor Author

yani commented Feb 14, 2023

Hi. Sorry for taking so much time. I might have some time tomorrow.

I'll have to look for a way to make sure it's tested correctly. I think the test case should just be that it doesn't throw an exception, which I think is correctly handled by PHPUnit which would just return false for the case if it does. I still have to look at any possible differences between using the dynamic property way of doing it.

@yani
Copy link
Contributor Author

yani commented Feb 15, 2023

I had to manually throw E_USER_NOTICE to keep current tests working but also implement the original overloading behavior.

I tested it on the project where I encountered the error and everything seems to be working as intended as far as I can tell.

@yani yani requested a review from compwright February 18, 2023 02:59
@yani
Copy link
Contributor Author

yani commented Mar 3, 2023

@compwright I'm not sure if you're waiting for me to mark your change request as done. But I'm unable to mark it as such.

If you're keeping this open because you don't like the E_USER_NOTICE, I could maybe try and figure out another way but I think this is as good as it gets.

@compwright compwright changed the title fix overloading behaviour fix: overloading behaviour Jan 8, 2024
@compwright compwright merged commit 3d43518 into compwright:master Jan 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants